<template>
	<view class="empty" style="margin-top: 300rpx;" v-if="list.length == 0">
		<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
		</u-empty>
	</view>
	<!-- 列表 -->
	<view class="min30_rl mintop30" v-else>
		<view v-for="(item,index) in list" @click="onNav(item.goods_id,item.is_type)">
			<view class="rad2 minbottom30 row"
				style="box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24); padding: 20rpx 30rpx;"
				v-if="item.is_type == 4">
				<view class="column" style="">
					<view class="row minbottom10">
						<view class="font700 size30 col0 omit2" style="align-items: flex-end;">
							{{ item.title }}
						</view>
						<!-- <view class="minau minright0 size26 col6 font500">
							{{ $com.format(item.create_time, 'yyyy-MM-dd') }}
						</view> -->
					</view>
					<view class="column">
						<view class="row size22 font500 align minbottom10" style="color: #808080;">
							<view class="size24" style="color: #FF2D10;">
								￥
							</view>
							<view class="size28 font700" style="color: #FF2D10;">
								{{ item.price }}
							</view>
							<!-- <view class="size24 col3 minleft10 font500">
								元/亩/年
							</view> -->
						</view>
						<view class="size28 minbottom10" v-if="item.age">
							{{ item.age }}年
						</view>
						<view class="row size22 font500 align minbottom10" style="color: #808080;" v-if="item.acres">
							<image src="@/static/index/land.png" mode="" style="width: 30rpx;height: 30rpx;">
							</image>
							{{ item.acres }}
						</view>
						<view class="size26 font500">
							{{ item.address }}
						</view>
					</view>
				</view>
			</view>
			<view class="rad2 minbottom30 row" style="box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24);"
				v-else-if="item.is_type == 2">
				<image :src="item.cover" style="width: 35%;height: 240rpx;border-radius: 20rpx 0 0 20rpx;">
				</image>
				<view class="column" style="padding: 20rpx;width: 59%;">
					<view class="row">
						<view class="font700 size30 col0 omit1" style="max-width: 240rpx;">
							{{ item.title }}
						</view>
						<view class="font500 size24 disflex align rad2 minleft20"
							style="background-color: #FFF3C9;color: #FF7A00;padding: 0 20rpx;">
							{{ item.price }}
						</view>
					</view>
					<view class="minto minbottom0">
						<view class="row size26 font500 align minbottom10" style="color: #808080;">
							司机：{{ item.age }}
						</view>
						<view class="row size24 font500 align minbottom10" style="color: #808080;">
							{{ item.address }}
						</view>
						<view class="row size24 font500 align" style="color: #FF7A00;">
							合作社已认证
							<!-- <view class="minau minright0 col0">
								{{ item.distance }}
							</view> -->
						</view>
					</view>
				</view>
			</view>
			<view class="rad2 minbottom30 row" style="box-shadow: 1rpx 1rpx 8rpx 2rpx rgba(206,188,172,0.24);" v-else>
				<image :src="item.cover" style="width: 35%;height: 240rpx;border-radius: 20rpx 0 0 20rpx;">
				</image>
				<view class="column" style="padding: 20rpx;width: 59%;">
					<view class="font700 size30 col0 minbottom10 omit1">
						{{ item.title }}
					</view>
					<view class="row">
						<view class="font500 size22 rad2"
							style="background-color: #DEEFD6;color: #60884D;padding: 2rpx 14rpx;">
							{{ item.classify_name }}
						</view>
						<view class="font500 size22 rad2 minleft10"
							style="background-color: #FFF3C9;color: #FF7A00;padding: 2rpx 14rpx;">
							{{ item.type }}
						</view>
					</view>
					<view class="minto minbottom0">
						<view class="row size22 font500 align minbottom10" style="color: #808080;">
							<view class="size24" style="color: #FF2D10;">
								￥
							</view>
							<view class="size28 font700" style="color: #FF2D10;">
								{{ item.price }}
							</view>
							<!-- <view class="size24 col3 minleft10 font500">
								元/亩/年
							</view> -->
							<view class="minau minright0" v-if="item.age">
								{{ item.age }}年
							</view>
						</view>
						<view class="row size22 font500 align" style="color: #808080;">
							<view class="row align" v-if="item.acres">
								<image src="@/static/index/land.png" mode="" style="width: 30rpx;height: 30rpx;">
								</image>
								{{ item.acres }}
							</view>
							<view class="minau minright0 omit1" style="width: 300rpx;text-align: right;">
								{{ item.address }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="margin-top: 50rpx;"><u-loadmore :status="status" /></view>
	</view>
	<!-- 列表 -->
</template>

<script>
	export default {
		data() {
			return {
				topHight: '',
				user_id: '',
				page: 1,
				status: 'loadmore',
				loadmore: [],
				list: []
			}
		},
		onLoad() {
			let app = uni.getSystemInfoSync()
			this.topHight = app.statusBarHeight
		},
		onShow() {
			//当前页面展示的时候他就执行该生命周期
			this.user_id = uni.getStorageSync('user_id');
			if (this.user_id) {
				//如果存在token
				this.getContacted()
				//按正常逻辑来讲 登录成功 我们是不是需要向服务器获取用户的信息？
				//那么我们一起来获取用户信息
			} else {
				this.$com.toast('您还未登录，正在前往登录')
				setTimeout(() => {
					this.$jump.nav('/mypackage/sign')
				}, 1000)
			}
		},
		onReachBottom() {
			if (this.page < 0) return;
			this.status = 'loading';
			this.page = ++this.page
			this.getContacted()
			setTimeout(() => {
				console.log(this.loadmore);
				if (this.loadmore.length == 0) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			async getContacted() {
				let {
					code,
					msg,
					data
				} = await this.$com.fetchGet("AppletAsking/contactedList", {
					page: this.page,
					user_id: this.user_id
				})
				if (code == 1) {
					if (this.page != 1) {
						this.loadmore = data.items
						for (var i = 0; i < data.items.length; i++) {
							this.list.push(data.items[i]); // 加载的数据追加在上一页后面
						}
					} else {
						this.loadmore = data.items
						this.list = data.items
					}
				} else {
					console.log(msg);
				}
			},
			onNav(id, is_type) {
				console.log(id, is_type);
				if (is_type == 4) {
					setTimeout(() => {
						this.$jump.switch('/pages/buy/buy')
					}, 1000)
				} else if (is_type == 2) {
					setTimeout(() => {
						this.$jump.nav('/indexpackage/machinery_info?id=' + id)
					}, 1000)
				} else if (is_type == 3) {
					setTimeout(() => {
						this.$jump.nav('/indexpackage/farmproduce_info?id=' + id)
					}, 1000)
				} else {
					setTimeout(() => {
						this.$jump.nav('/indexpackage/info?id=' + id)
					}, 1000)
				}
			}
		}
	}
</script>

<style>
</style>